#pragma once
#include "RBTree.h"


namespace bit
{

	template<class K, class V>
	class map
	{
		struct MapKeyOfT
		{
			K operator()(const pair<K, V>& p)
			{
				return p.first;
			}
		};
	public:
		typedef typename RBTree< K,pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree< K,pair<const K, V>, MapKeyOfT>::ConstIterator const_iterator;

		pair<iterator,bool> insert(const K& key, const V& val)
		{
			return _rbt.Insert(make_pair(key,val));
		}
		void inorder()
		{
			_rbt.InOrder();
		}
		iterator begin()
		{
			return _rbt.Begin();
		}
		iterator end()
		{

			return _rbt.End();
		}
		const_iterator begin()const
		{
			return _rbt.Begin();
		}
		const_iterator end()const
		{

			return _rbt.End();
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _rbt.Insert(make_pair(key,key));
			return ret.first->second;
		}
	private:
		RBTree<K,pair<const K,V>,MapKeyOfT> _rbt;
	};
}